
import { DefaultLayout, GraphNode } from "@/js/components/GraphNode"
import { GraphView } from "@/js/components/GraphView"
import { InputLinkNodeAny, InputLinkNodeNumber, InputLinkNodeFlow } from "@/js/components/InputLinkNode"

export class Reduce extends GraphNode{
    layout?: DefaultLayout
    static menuName = "减法 -"
    name = "减法 -"
    load(){
        super.load()

        const layout = new this.DefaultLayout(this, this.graphView as GraphView, false, false)
        this.layout = layout
        this.appendChild(layout.container)

        layout.main?.left.appendChild(new InputLinkNodeNumber(this, this.graphView as GraphView, {
            name: "value1",
            desc: '值',
            model: "entry",
        }))

        layout.main?.left.appendChild(new InputLinkNodeNumber(this, this.graphView as GraphView, {
            name: "value2",
            desc: '值',
            model: "entry",
        }))

        layout.main?.right.appendChild(new InputLinkNodeNumber(this, this.graphView as GraphView, {
            name: "value3",
            desc: '值',
            showInput: false,
            model: "output",
            linkMaxCount: 1000
        }))
    }
}

Reduce.parser =  ({node,next, data})=>{
    data.value1 = data.value1 || next(node.enters.value1) || node.userData.enters.value1 || 0
    data.value2 = data.value2 || next(node.enters.value2) || node.userData.enters.value2 || 0

    return `${data.value1}-${data.value2}`
}